CC=gcc
CXX=g++
CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS)
CPPFLAGS=-Wall -ansi $(DEBUG) $(EXCEPTIONS) $(CPPINCLUDES) $(DEFINITIONS) $(CPPMISCFLAGS)
DEBUG=-O3 -g3
CMISCFLAGS=
CPPMISCFLAGS=-DGIMI_CLIENT_API=10303
DEFINITIONS=-DLINUX_OS -DGIMI_NO_DATATYPE_INCLUDES
EXCEPTIONS=-fexceptions
CINCLUDES=-I.
CPPINCLUDES=-I.

LD=g++
LDFLAGS=
LIBS=-lrt -lpthread

GDIR=../../../
SRCSC=
SRCSCPP=mcltest.cpp
VPATH=
CPPGIMI=
CGIMI=

## Build GIMI and it's dependencies.
## Files are set to CGIMI and CPPGIMI variables
include Makefile.mcl

CGIMI += $(CMCL)
CPPGIMI += $(CPPMCL)

POSEMCL=CParticleFilter.cpp PoseMCL.cpp testPoseMCL.cpp
OBS_POSEMCL=$(POSEMCL:.cpp=.opp)

## Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o) $(CGIMI:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp) $(CPPGIMI:.cpp=.opp)

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

all: mcltest testPoseMCL

mcltest: $(OBJSC) $(OBJSCPP)
	$(LINK) -o $@ $(OBJSC) $(OBJSCPP)
testPoseMCL: $(OBS_POSEMCL)
	$(LINK) -o $@ $(OBS_POSEMCL)

clean:
	rm -f $(OBJSC) $(OBJSCPP) mcltest *.out *~ *.d *.dpp

## Compile rule for all .o (.c) file
%.o:    %.c
				$(COMPILEC) -o $@ $<

## Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
				$(COMPILECPP) -o $@ $<

## Dependency generation rule: For all required '.d' files
%.d:	  %.c
				$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
				sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
				rm -f $@.$$$$

## Dependency generation rule: For all required '.dpp' files
%.dpp:	%.cpp
				$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
				sed 's,\($*\)\.o[ :]*,\1.opp $@ : ,g' < $@.$$$$ > $@; \
				rm -f $@.$$$$

%.h:	%.h

# Include dependency rules
-include $(SRCSCPP:.cpp=.dpp) $(CPPGIMI:.cpp=.dpp)
-include $(SRCSC:.c=.d) $(CGIMI:.c=.d)
